package com.bw.module_merchant.activity

import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.blankj.utilcode.util.SPUtils
import com.bw.lib_common.view.BaseMvvmFragment
import com.bw.module_merchant.R

import com.bw.module_merchant.adapter.EnterpriseRecordAdapter
import com.bw.module_merchant.databinding.FragmentMerchantRecordBinding
import com.bw.module_merchant.vm.EnterpriseRecordViewModel

import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MerchantRecordFragment : BaseMvvmFragment<FragmentMerchantRecordBinding>() {
    private val mAdapter = EnterpriseRecordAdapter()
    private val viewModel : EnterpriseRecordViewModel by activityViewModels()
    override fun getFragmentState(state: Bundle) {

    }

    override fun saveFragmentState(onState: Bundle) {

    }

    override fun bindLayout(): Int  = R.layout.fragment_merchant_record

    override fun initView() {

        binding.rv.adapter = mAdapter
        binding.rv.layoutManager = LinearLayoutManager(requireContext())

        mAdapter.setOnItemClickListener { adapter, view, position ->
            SPUtils.getInstance().put("merchantId" , mAdapter.data[position].id)
            startActivity(Intent(requireContext() , MerchantDetailActivity::class.java))
        }

        viewModel.getMerchantRecordList()

        viewModel.mSuccessLiveData.observe(viewLifecycleOwner){
            mAdapter.data.addAll( it.data)
            mAdapter.notifyDataSetChanged()
        }

    }


}